package com.yuexun.dhdoctor.module.Contract.presenter.impl;


import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.Contract.bean.CreateGroup;
import com.yuexun.dhdoctor.module.Contract.bean.GoupExist;
import com.yuexun.dhdoctor.module.Contract.model.ICreateGroupModel;
import com.yuexun.dhdoctor.module.Contract.presenter.ICreateGroupPresenter;
import com.yuexun.dhdoctor.module.Contract.ui.view.ICreateGroupView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/7/25.
 */
public class CreateGroupPrensenter implements ICreateGroupPresenter {
    private ICreateGroupView view;
    private ICreateGroupModel model;

    public CreateGroupPrensenter(ICreateGroupModel model, ICreateGroupView view) {
        this.model = model;
        this.view = view;
    }



    @Override
    public void createGroup(Map<String, String> praise) {
        model.createGroup(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<CreateGroup>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("创建群组失败");
                               }

                               @Override
                               public void onNext(CreateGroup createGroup) {
                                   view.showCreateGroup(createGroup);
                               }
                           }
                );
    }

    @Override
    public void isGroupExisit(Map<String, String> praise) {
        model.isGroupExisit(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<GoupExist>>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast(e.toString());
                               }

                               @Override
                               public void onNext(BaseEntity<GoupExist> createGroup) {
                                   view.showGroup(createGroup);
                               }
                           }
                );
    }
}
